package com.bdqn.staffmanagementsystem.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

@Configuration
public class MyLocaleResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        System.out.println("dsjod vokd");
//        获取请求中的国际化参数
        String language = request.getParameter("language");
//        获取默认的语言
        Locale locale = Locale.getDefault();
//      如果请求携带了国际化参数，没有就是用默认的
        System.out.println(language!=null);
        if (language!=null){
            String[] s = language.split("_");
//            返回国家地区的语言
            System.out.println(s);
            locale = new Locale(s[0],s[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
    }
}
